﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;
using SSP;
using SSPDemo;

/*
 * Quick-and-dirty Singleton Audio Engine
 * 
 * To use, call Load from the Game LoadContent() method, passing in the content manager
 * 
 * Only works with .wav files for now; .mp3s require different handling
 * 
 * To add new music/sfx:
 *  Add it into the content project
 *  Manually create another SoundEffect member 
 *  Duplicate what you see with the rest (Load it, create a new Play_() method, etc)
 */

namespace SSP
{
    public sealed class SSPAudio
    {
        private static readonly SSPAudio instance = new SSPAudio();

        public SoundEffect background_music;
        public SoundEffectInstance bgm_instance;
        public SoundEffect attack;
        public SoundEffect kill;
        public SoundEffect death;

  
        private SSPAudio() 
        {
        }

        public static SSPAudio GetInstance
        {
            get
            {
                return instance;
            }
        }

        // Loads and initializes audio content
        // Must be called in Game LoadContent()
        public void Load(ContentManager content)
        {
            background_music = content.Load<SoundEffect>("SPO");
            attack = content.Load<SoundEffect>("attack");
            death = content.Load<SoundEffect>("death");
            kill = content.Load<SoundEffect>("kill");

            ContentLoaded();
        }

        private void ContentLoaded()
        {
            bgm_instance = background_music.CreateInstance();
            bgm_instance.IsLooped = true;

            //StartBGM();
        }

        // The below methods can be called anywhere once Load() has been called
        public void StartBGM()
        {
            background_music.Play();
        }

        public void AttackSFX()
        {
            attack.Play();
        }

        public void DeathSFX()
        {
            death.Play();
        }
        public void KillSFX()
        {
            kill.Play();
        }
    }
}
